package com.powernode.lambda.stream;

import com.powernode.lambda.Student;

import java.util.IntSummaryStatistics;
import java.util.stream.*;

/**
 * 测试stream相关Api 三种基本流
 * intStream、longStream、doubleStream
 * 方法：mapToObj、boxed、summaryStatistics衍生统计方法
 * 对象流转换为基本流：mapToInt、mapToLong、mapToDouble
 */
public class Stream12 {
    public static void main(String[] args) {
        IntStream intStream = IntStream.of(97, 98, 99);
        LongStream longStream = LongStream.of(1L, 2L, 3L);
        DoubleStream doubleStream = DoubleStream.of(1.0, 2.0, 3.0);

        Stream<Integer> integerStream = Stream.of(1, 2, 3);

        //mapToObj 转换为obj流
//        intStream.mapToObj(x->Character.toChars(x)).forEach(System.out::println);
        //intStream.boxed() 转为Integer流
        //intStream.boxed().forEach(System.out::println);
        IntSummaryStatistics statistics = intStream.summaryStatistics();
        System.out.println("statistics.getSum() = " + statistics.getSum());
        System.out.println("statistics.getAverage() = " + statistics.getAverage());
        System.out.println("statistics.getMax() = " + statistics.getMax());
        System.out.println("statistics.getMin() = " + statistics.getMin());
        System.out.println("statistics.getCount() = " + statistics.getCount());

        Stream<Student> stream = Stream.of(
                new Student("张无忌", 26, "男"),
                new Student("赵敏", 22, "女"),
                new Student("周芷若", 21, "女"),
                new Student("女波斯圣使", 30, "女"),
                new Student("灭绝师太", 30, "女"),
                new Student("张三丰", 100, "男")
        );

        //对象流转基本流
        stream.mapToInt(x->x.getAge()).forEach(System.out::println);
    }

}
